<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;
use \app\index\model\CronHandler;
use think\Session;
use app\index\model\User;

class Active extends Controller{
	public $userObj;

	public function _initialize(){
        $this->userObj = new User(cookie('user_id'),cookie('login_key'));
		if(!$this->userObj->loginStatus){
			echo "Bad request";
			exit();
        }
        if($this->userObj->groupData["id"] != 1){
			$this->error('你无权访问此页面',403,$this->siteOptions);
		}
    }
    public function Query(){
        $machineCode = input('param.key');
        if (is_null($machineCode) || $machineCode == "") {
            return ["error"=>1,"msg"=>"Bad Reqeust"];
        }
        $private_content = file_get_contents(__DIR__.'/private.pem');
        $private_key = openssl_pkey_get_public($private_content);
      
        if(!$private_key){
            return ["error"=>1,"msg"=>"私钥不可用"];
        }
        $return_en = openssl_public_encrypt($machineCode, $crypted, $private_key);
        if(!$return_en){
            return ["error"=>1,"msg"=>"加密失败,请检查RSA秘钥"];
        }
        return ["error"=>200,"active_code"=>base64_encode($crypted)];
    }


}
